<template>
    <teleport to="#loader">
        <div 
            class="d-flex justify-content-center align-items-center h-100 loading-container"
            :style="{background:background || ''}"
            >
            <div class="loading-content">
                <div class="spinner-border " :style="{color:color || ''}" role="status">
                        <span class="sr-only visually-hidden"></span>
                </div>
                <p  :style="{color:color || ''}"  v-if="text">{{text}}</p>
            </div>
        </div>
    </teleport>
</template>

<script lang="ts">
import {defineComponent,onUnmounted} from 'vue'
export default defineComponent({
props: {
    text: {
        type: String,
        default: ""
    },
    background: {
        type: String
    },
    color: {
        type:String,
        default: '#0d6efd'
    }
},
setup() {
    const node = document.createElement('div')
    node.id = "loader"
    document.body.appendChild(node)

    onUnmounted(() => {
        document.body.removeChild(node)
    })
    return
}
})
</script>

<style scoped>
    .loading-container {
        z-index: 100;
        background: rgba(255, 255, 255, 0.5);
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
    }
    .loading-content {
        text-align: center;
    }
</style>